package com.blog.dao.adminannouncement;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.management.loading.PrivateClassLoader;

import com.blog.dao.conn.BaseDao;
import com.blog.dao.conn.ParamSet;
import com.blog.dao.conn.RowDatas;
import com.blog.entity.NoticeEntity;

public class AdminNoticeDao extends BaseDao {

	private RowDatas<NoticeEntity> notice = new RowDatas<NoticeEntity>() {

		@Override
		public NoticeEntity getRowData(ResultSet rs) throws SQLException {
			NoticeEntity ne=  new NoticeEntity();
			ne.setNotice_content(rs.getString("notice_content"));
			ne.setNotice_time(rs.getDate("notice_time"));
			ne.setNotice_personid(rs.getString("notice_personid"));
			ne.setNotice_title(rs.getString("notice_title"));
			return ne;
		}
	};
	
	/**
	 * 删除公告,草稿箱公告,根据状态分类公告
	 */
	public List<NoticeEntity> queryAllNoticeByTypes(int status) {
		String sql = "select notice_personid,notice_time,notice_title,notice_content from tb_notice \r\n" + 
				"where notice_status = ?";
		return queryList(sql, new ParamSet(status),notice);
	}
	
	/**
	 * 所有公告里面根据日期查询公告
	 */
	public List<NoticeEntity> queryNoticeByTime(String onedate,String twodata,int flag) {
		String sql = "select notice_personid,notice_time,notice_title,notice_content from tb_notice \r\n" + 
				"where notice_time>? and notice_time<? and notice_status = ?";
		return queryList(sql,new ParamSet(onedate,twodata,flag), notice);
	}
	
	/**
	 * 所有公告里面模糊查询公告
	 */
	public List<NoticeEntity> queryNoticeByInput(String str,int flag) {
		String sql = "select * from tb_notice where 1=1 and notice_title like ? and notice_status = ?";
		return queryList(sql,new ParamSet("%"+str+"%",flag), notice);
	}
	
	/**
	 * 添加公告
	 */
	public int addNotice(NoticeEntity notice) {
		int row = 0;
		String sql = "insert into tb_notice(notice_personid,notice_time,notice_title,notice_content,notice_status)\r\n" + 
				"VALUES(?,?,?,?,?)";
		row = updateExecuted(sql,new ParamSet(notice.getNotice_personid(),notice.getNotice_time(),notice.getNotice_title(),notice.getNotice_content(),notice.getNotic_status()));
		return row;
		
	}
	
	
	
	
	
	
}
